﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

using MvcSystemsCommander.Models.Entity;

namespace MvcSystemsCommander.Models.Repository
{
    public class UnitOfWork : IUnitOfWork
    {
        private readonly DbContext context;

        public UnitOfWork(DbContext nContext = null)
        {
            if (nContext == null) { nContext = new MSCEntitiesContainer(); }
            this.context = nContext;
        }

        internal DbSet<T> GetDbSet<T>()
            where T : class
        {
            return context.Set<T>();
        }

        public void Commit()
        {
            context.SaveChanges();
        }

        public void Dispose()
        {
            context.Dispose();
        }
    }
}